package main

import (
	"log"
	"time"
)

//type T = struct {}
type T struct{}

func worker(id int, ready <-chan T, done chan<- T) {
	<-ready

	log.Print("Worker#", id, "Starting to Work")
	// mock workload
	time.Sleep(time.Second * time.Duration(id+1))

	log.Print("Worker#", id, "Done")
	done <- T{} // notify main goroutine (N : 1)
}

func main() {
	log.SetFlags(0)

	ready, done := make(chan T), make(chan T)
	go worker(0, ready, done)
	go worker(1, ready, done)
	go worker(2, ready, done)

	// mock initializing
	time.Sleep(time.Second * 3 / 2)

	// 1 : M notification
	//ready <- T{}
	//ready <- T{}
	//ready <- T{}
	close(ready)

	// waiting for M : 1 notification
	<-done
	<-done
	<-done
}
